home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Software Contest 3
/
FM Towns Software Contest 3.iso
/
exp
/
astral
/
a1
/
game
/
source
/
asmsub.asm
< prev
next >
Wrap
Assembly Source File
|
1994-01-07
|
8KB
|
418 lines
;*******************************************************************
;*** ***
;*** ワイヤーフレームプログラム用 アセンブラサブルーチン群 ***
;*** ***
;*******************************************************************
.386p
;============================================================================
; シンボル設定
;============================================================================
CRTC_addr_reg equ 0440h ;CRTC
CRTC_data_reg equ 0442h
VSYNC_clear_reg equ 05cah ;VSYNC割り込み要因クリアレジスタ
PIC_ocw1m equ 0002h ;PIC
PIC_ocw1s equ 0012h
PIC_ocw2m equ 0000h
PIC_ocw2s equ 0010h
PIC_ocw3m equ 0000h
PIC_ocw3s equ 0010h
PIC_isrm equ 0000h
PIC_isrs equ 0010h
CRTC_reg equ 0440h
PAD1_in equ 04d0h
PAD2_in equ 04d2h
PAD_out equ 04d6h
VRAM_seg equ 0120h ;VRAM(2画面モード)セレクタ
int_VSYNC equ 000bh ;VSYNCの割り込み番号
clear_color equ 6 ;画面消去で塗り潰す色
DOSX_nv_get equ 2502h ;DOS-Extenderのファンクション
DOSX_rv_get equ 2503h
DOSX_nv_set equ 2504h
DOSX_rv_set equ 2505h
DOSX_r2nv_set equ 2506h
DOSX_rnv_set equ 2507h
DOSX_hdv_get equ 250ch
;============================================================================
; データ領域
;============================================================================
DSEG segment dword public 'DATA'
n_vect_seg dw 0 ;Nativeベクタ保存領域
n_vect_off dd 0
r_vect dd 0 ;Realベクタ保存領域
handler_main dd 0 ;割り込みハンドラのエントリ
ocw1m_buf db 0 ;PICのレジスタ保存領域
ocw1s_buf db 0
int_flag dd 0 ;多重割り込み防止用フラグ
Vbuf dd 6 dup(?)
DSEG ends
;============================================================================
; コード領域
;============================================================================
CSEG segment dword public 'CODE'
assume cs:CSEG,ds:DSEG
;----------------------------------------------------------------------------
; int VSYNC_set(void (*entry)(void))
; VSYNCの割り込みハンドラを登録する関数.
; この関数はかなり893(Ya・Ku・Za)だなぁ.
; ERiCON,ARiCONなんかから立ち上げると暴走するよ.
; Towns-OS V2.1コンソールだとまともに動くけどネ.
;----------------------------------------------------------------------------
public VSYNC_set
db 'VSYNC_set',9
VSYNC_set proc near
push ebp
mov ebp,esp
push edi
push esi
push ebx
push ds
push es
mov eax,ss:[ebp]+4+4
mov handler_main,eax
mov ax,DOSX_hdv_get ;VSYNC割り込みのベースを求める
int 21h
jb error
mov cl,ah
add cl,int_VSYNC-8
mov ax,DOSX_nv_get ;Nativeモードの割り込みベクトルを保存
int 21h
jb error
mov ax,es
mov n_vect_seg,ax
mov n_vect_off,ebx
mov ax,DOSX_rv_get ;Realモードの割り込みベクトルを保存
int 21h
jb error
mov r_vect,ebx
mov ax,DOSX_r2nv_set ;新しく割り込みベクトルをセット
push ds
push cs
pop ds
mov edx,offset handler
int 21h
jb error
pop ds
in al,PIC_ocw1s ;VSYNC割り込みを許可&他の割り込みを禁止
mov ocw1s_buf,al
and al,11110111b
out PIC_ocw1s,al
pop es
pop ds
pop ebx
pop esi
pop edi
pop ebp
mov eax,0
ret
error:
pop es
pop ds
pop ebx
pop esi
pop edi
pop ebp
mov eax,1
ret
VSYNC_set endp
;----------------------------------------------------------------------------
; 割り込みハンドラの本体
;----------------------------------------------------------------------------
handler:
push ds
push es
push fs
push gs
pushad
mov dx,VSYNC_clear_reg ;VSYNC割り込み要因をクリア
out dx,al
call handler_main ;割り込みハンドラを呼出し
mov al,00100000b ;EOIを発行
out PIC_ocw2s,al
mov al,00001011b
out PIC_ocw3s,al
in al,PIC_isrs
cmp al,0
jnz pass_eoi
mov al,00100000b
out PIC_ocw2m,al
pass_eoi:
popad
pop gs
pop fs
pop es
pop ds
exit_handler:
iretd
;----------------------------------------------------------------------------
; void VSYNC_end(int dummy)
; VSYNC割り込みベクトルを元に戻す関数.
; ERiCON,ARiCONなんかだとこれを実行しても無駄だよ~ん.
;----------------------------------------------------------------------------
public VSYNC_end
db 'VSYNC_end',9
VSYNC_end proc near
push ebp
push edi
push esi
push ebx
push ds
push es
mov al,ocw1s_buf ;VSYNC割り込みマスクを元に戻す
out PIC_ocw1s,al
; mov al,ocw1m_buf
; out PIC_ocw1m,al
mov ax,DOSX_hdv_get ;VSYNC割り込みのベースを求める
int 21h
mov cl,ah
add cl,int_VSYNC-8
mov ax,DOSX_rnv_set ;割り込みベクトルを元に戻す
mov bx,n_vect_seg
mov ds,bx
mov edx,n_vect_off
mov ebx,r_vect
int 21h
exit2:
pop es
pop ds
pop ebx
pop esi
pop edi
pop ebp
ret
VSYNC_end endp
;----------------------------------------------------------------------------
; int SND_init2(char *work)
;----------------------------------------------------------------------------
public SND_init2
db 'SND_init2',9
SND_init2 proc near
push edi
push esi
push gs
push fs
mov edi,ss:[esp]+16+4
mov ax,110h
mov fs,ax
mov ah,00h
call pword ptr fs:80h
pop fs
pop gs
pop esi
pop edi
ret
SND_init2 endp
snd_entry proc far
push edx
push eax
push fs
mov dx,04e9h
in al,dx
and al,00001000b
jz snd_exit
mov ax,110h
mov fs,ax
mov ah,51h
call pword ptr fs:80h
snd_exit:
pop fs
pop eax
pop edx
ret
snd_entry endp
;----------------------------------------------------------------------------
; void CRTC_out(int addr,int num)
; CRTCのレジスタ書き込み
;----------------------------------------------------------------------------
public CRTC_out
db 'CRTC_out',8
CRTC_out proc near
mov dx,CRTC_reg
mov al,ss:[esp]+4
out dx,al
add dx,2
mov ax,ss:[esp]+8
out dx,ax
ret
CRTC_out endp
;----------------------------------------------------------------------------
; int pad_in(void);
; パッドを読み出す(SND_joy_in_1相当)
;----------------------------------------------------------------------------
public pad_in
db "pad_in",6
pad_in proc near
mov dx,PAD_out
mov al,00101111b
out dx,al
mov eax,0
mov dx,PAD1_in
in al,dx
ret
pad_in endp
;----------------------------------------------------------------------------
; void cls(int page,int color)
; 画面消去の関数
;----------------------------------------------------------------------------
public clear_screen
db 'clear_screen',12
clear_screen proc near
push esi
push edi
push es
mov edi,ss:[esp]+12+4
shl edi,17
mov ax,VRAM_seg
mov es,ax
mov ecx,256*256*2/4
mov eax,ss:[esp]+12+8
shl eax,16
add eax,ss:[esp]+12+8
rep stosd
pop es
pop edi
pop esi
ret
clear_screen endp
;----------------------------------------------------------------------------
; void wait_VSYNC(void)
; VSYNCを待つ関数
;----------------------------------------------------------------------------
public wait_VSYNC
db 'wait_VSYNC',10
wait_VSYNC proc near
loop1:
mov dx,CRTC_addr_reg
mov al,30
out dx,al
inc dx
inc dx
in ax,dx
and ax,0000010000000000b
jz loop1
ret
wait_VSYNC endp
;----------------------------------------------------------------------------
; void chgpage(int page);
; 表示ページを切り換える関数
;----------------------------------------------------------------------------
public chgpage
db 'chgpage',7
chgpage proc near
mov dx,CRTC_addr_reg
mov al,17
out dx,al
inc dx
inc dx
mov ax,ss:[esp]+4
shl ax,15
out dx,ax
ret
chgpage endp
CSEG ends
end